<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>登录</h1>
    <!-- <form action="/register" method="post"> -->
    用户名：<input type="text" id="user"><br>
    密码：<input type="text" id="pass"><br>
    <span></span><br>
    <button>注册</button>
    <!-- </form> -->
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <script>
        $('button').click(() => {
            //获取用户输入的数据
            let username = $('#user').val();
            let password = $('#pass').val();
            // console.log(username,password);

            //ajax请求,将用户输入的账号和密码传送给ajax请求后端
            $.ajax({
                type:'post',
                url:'/register',
                //将用户的数据传送给后台
                data:{
                    username,
                    password,
                },
                success(res){
                    console.log(res);
                    if(res.code == 200){
                        location.href = '/2.login.html';
                    }else{
                        $('span').html(res.msg);
                    }
                }
            })
          
        })
    </script>
</body>

</html>